<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>保存this</title>
</head>

<body>
    <div id="div1">我是一个 div</div>
    <script>
        window.id = 'window';
        document.getElementById('div1').onclick = function () {
            alert(this.id); // 输出：'div1'
            var that = this; // 保存 div 的引用
            var callback = function () {
                alert(this.id); // 输出：'window'
                alert(that.id); // 输出：'div1'
            }
            callback();
        };
    </script>
</body>

</html>